package Library;
import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.print.attribute.DateTimeSyntax;

import Server.DBmethods;

/**
 * thread of the server that run in the backhround
 * his job is to check every 24 hours if there are student that have to return book tomrrow so he notify them
 * and
 * @author Maor
 *
 */
public class Reminder implements Runnable{

	private final long sleepTime=24*60*60*1000;
	
	public void run() {
		// TODO Auto-generated method stub
		while(true)
		{
		try {
			tasks();
			Thread.sleep(sleepTime);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		}
	}

	/**
	 * called one time in day and to the checks that described up 
	 */
	private void tasks() {
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
		Calendar cal = Calendar.getInstance();
		String  today = dateFormat.format(cal.getTime());
		Date date;
		try {
			date = dateFormat.parse(today);
			DBmethods.TomorrowRetrunBook(date); 
			DBmethods.bookDontWait(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//DBmethods.CancelOrdeForBook(today);
		
	}



}
